//
//  CheckXunjianCell.m
//  Qihuo
//
//  Created by Vencoo on 13-12-19.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "CheckXunjianCell.h"
#import "ASIFormDataRequest.h"
@implementation CheckXunjianCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.frame = CGRectMake(0, 0, 900, 40);
        _timeLabel = [UILabel new];
        _timeLabel.font = [UIFont systemFontOfSize:30];
        _timeLabel.textAlignment = 0;
        CGSize mySz = [[NSString stringWithFormat:@"2013-12-23   11:45:24"] sizeWithFont:_timeLabel.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        _timeLabel.frame = CGRectMake(20, (self.frame.size.height - mySz.height)/2, mySz.width, mySz.height);
        [self addSubview:_timeLabel];
        
        _nameLabel = [UILabel new];
        _nameLabel.font = [UIFont systemFontOfSize:30];
        mySz = [[NSString stringWithFormat:@"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"]sizeWithFont:_nameLabel.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        _nameLabel.textAlignment = 2;
        _nameLabel.frame = CGRectMake(self.frame.size.width - mySz.width - 140, (self.frame.size.height - mySz.height)/3, mySz.width, mySz.height);
        [self addSubview:_nameLabel];
        
        _cellBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_cellBtn setTitle:@"查看签到记录" forState:UIControlStateNormal];
        _cellBtn.titleLabel.font = [UIFont systemFontOfSize:30];
        _cellBtn.frame = CGRectMake(_nameLabel.frame.origin.x + _nameLabel.frame.size.width + 20, _nameLabel.frame.origin.y, 180, mySz.height);
        [_cellBtn addTarget:self action:@selector(checkQianRecord:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cellBtn];
    }
    return self;
}
- (void)checkQianRecord:(id)sender
{
    [MBProgressHUD showHUDAddedTo:self.delegate.view animated:YES];
    NSURL *queryUrl = [NSURL URLWithString:seeQianDaoRecord];
    ASIFormDataRequest *obtainFloor = [ASIFormDataRequest requestWithURL:queryUrl];
    [obtainFloor setPostValue:self.delegate.sendCheckTime forKey:@"checkTime"];
    [obtainFloor setPostValue:[NSString stringWithFormat:@"%i",self.delegate.checkAreaNumber]forKey:@"checkArea"];
    [obtainFloor startAsynchronous];
    obtainFloor.delegate = self;
    [obtainFloor setDidFinishSelector:@selector(requestDone:)];
    [obtainFloor setDidFailSelector:@selector(requestFail)];
    

}
- (void)requestDone:(ASIFormDataRequest *)request
{
    [MBProgressHUD hideHUDForView:self.delegate.view animated:YES];
    NSString *response = [request responseString];
    if (response)
    {
        NSDictionary *queryDic = [response JSONValue];
        self.delegate.recordView.hidden = 0;
        self.delegate.navigationController.navigationBar.hidden = 1;
        NSArray *queryDataArr = [queryDic objectForKey:@"data"];
        self.delegate.resignRecords = queryDataArr;
        [self.delegate.checkTableView reloadData];
        NSLog(@"jilu%@",queryDataArr);
        
        self.delegate.startDate.text = [[[queryDataArr firstObject]valueForKey:@"regTime"]substringWithRange:NSMakeRange(0, 10)];
        self.delegate.endDate.text = [[[queryDataArr lastObject]valueForKey:@"regTime"]substringWithRange:NSMakeRange(0, 10)];
        self.delegate.startTime.text = [[[queryDataArr firstObject]valueForKey:@"regTime"]substringWithRange:NSMakeRange(11, 8)];
        self.delegate.endTime.text = [[[queryDataArr lastObject]valueForKey:@"regTime"]substringWithRange:NSMakeRange(11, 8)];
        self.delegate.resumeTime.text = [NSString stringWithFormat:@"%i",queryDataArr.count];
    }
    else
    {
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"没有签到记录或网络无法连接！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertV show];
    }
}
- (void)requestFail
{
    [MBProgressHUD hideHUDForView:self.delegate.view animated:YES];
    UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"没有签到记录或网络无法连接！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alertV show];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)dealloc
{
    [super dealloc];
}
@end
